package com.chen.blue.controller.admin.business;

import com.chen.blue.annotation.permission.DataPermission;
import com.chen.blue.domain.dto.business.update.ContestApplyActiveDtoEdit;
import com.chen.blue.domain.query.business.ContestApplyActiveQuery;
import com.chen.blue.domain.query.business.ContestApplyRecordQuery;
import com.chen.blue.domain.vo.business.ContestApplyActiveVo;
import com.chen.blue.domain.vo.business.ContestApplyRecordVo;
import com.chen.blue.exception.e.DtoNullException;
import com.chen.blue.result.DataResult;
import com.chen.blue.result.R;
import com.chen.blue.service.business.IContestApplyActiveService;
import com.chen.blue.service.business.IContestApplyRecordService;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * Created By CLT On 2024/5/24.
 */
@SuppressWarnings("all")
@ApiSort(998)
@Api(tags = "申报管理-赛事审核模块")
@Validated
@RestController
@RequestMapping("/contest/active/audit")
@PreAuthorize("hasAnyRole('ROLE_faculty_manager', 'ROLE_faculty_charge', 'ROLE_office_manager', 'ROLE_office_charge', 'ROLE_school_boss')")
public class ContestApplyActiveAuditController {

    @Resource
    private IContestApplyActiveService iContestApplyActiveService;

    @Resource
    private IContestApplyRecordService iContestApplyRecordService;

    @ApiOperation(value = "竞赛申请审核(驳回：回到所处阶段的初始状态；通过：进入下一阶段的初始阶段)",
            notes = "竞赛申请审核(驳回：回到所处阶段的初始状态；通过：进入下一阶段的初始阶段)")
    @PutMapping("/edit")
    public R updateById(@RequestBody @Valid ContestApplyActiveDtoEdit contestApplyActiveDtoEdit) throws DtoNullException {

        return iContestApplyActiveService.updateContestApplyActiveById(contestApplyActiveDtoEdit) ? R.success() : R.faild();

    }

    @ApiOperation(value = "人员信息审核(驳回：回到所处阶段的初始状态；通过：进入下一阶段的初始阶段)",
            notes = "人员信息审核(驳回：回到所处阶段的初始状态；通过：进入下一阶段的初始阶段)")
    @PutMapping("/edit/personInfo")
    public R auditPersonInfo(@RequestBody @Valid ContestApplyActiveDtoEdit contestApplyActiveDtoEdit) throws DtoNullException {

        return iContestApplyActiveService.updateContestApplyActiveRelationPerson(contestApplyActiveDtoEdit) ? R.success() : R.faild();

    }

    @ApiOperation(value = "竞赛结果审核(驳回：回到所处阶段的初始状态；通过：进入下一阶段的初始阶段)",
            notes = "竞赛结果审核(驳回：回到所处阶段的初始状态；通过：进入下一阶段的初始阶段)")
    @PutMapping("/edit/contest/result")
    public R auditContestResult(@RequestBody @Valid ContestApplyActiveDtoEdit contestApplyActiveDtoEdit) throws DtoNullException {

        return iContestApplyActiveService.updateContestResult(contestApplyActiveDtoEdit) ? R.success() : R.faild();

    }

    @ApiOperation(value = "多条件查询待审核(已配数据权限)", notes = "多条件查询待审核(已配数据权限)")
    @DataPermission
    @PostMapping("/query")
    public R<DataResult<List<ContestApplyActiveVo>>> query(@RequestBody ContestApplyActiveQuery contestApplyActiveQuery) throws DtoNullException {

        return R.success(iContestApplyActiveService.queryContestApplyActive(contestApplyActiveQuery));

    }

    @ApiOperation(value = "ID查询待审核(已配数据权限)", notes = "ID查询待审核(已配数据权限)")
    @DataPermission
    @GetMapping("/queryById/{id}")
    public R<DataResult<Map<String, Object>>> queryById(@PathVariable("id") Long id) throws DtoNullException {

        return R.success(iContestApplyActiveService.queryContestApplyActiveById(id));

    }

    @ApiOperation(value = "多条件查询已审核(已配数据权限)", notes = "多条件查询已审核(已配数据权限)")
    @DataPermission
    @PostMapping("/queryRecordByAuditPerson")
    public R<DataResult<List<ContestApplyRecordVo>>> queryRecordByAuditPerson(@RequestBody ContestApplyRecordQuery contestApplyRecordQuery) throws DtoNullException {

        return R.success(iContestApplyRecordService.queryContestApplyRecordByAuditPerson(contestApplyRecordQuery));

    }

    @ApiOperation(value = "ID查询已审核", notes = "ID查询已审核(包含人员，文件等信息)")
    @GetMapping("/queryRecordById/{id}")
    public R queryContestApplyRecordById(@PathVariable("id") Long recordId) throws DtoNullException {

        return R.success(iContestApplyRecordService.queryContestApplyRecordById(recordId));

    }

}
